﻿using System.ComponentModel.DataAnnotations.Schema;

namespace project1.Models
{
    public class OrderDetail//指的是order中一个商品项的详细信息
    {
        public string orderdetailId { get; set; }

        public int orderIndex { get; set; }

        public string? GoodsId { get; set; }

        [ForeignKey("GoodsId")]

        public Goods? GoodsItem { get; set; }

        public string? GoodsName { get => GoodsItem != null ? this.GoodsItem.goodname : ""; }

        public double? oneitemPrice { get => GoodsItem != null ? this.GoodsItem.goodprice : 0; }

        public string orderId { get; set; }

        public int Quantity_of_this_item { get;set; }

        public OrderDetail() { 
            orderdetailId= Guid.NewGuid().ToString();
        }

        public OrderDetail(int index,Goods good,int quantity)
        {
            this.orderIndex = index;
            this.GoodsItem = good;
            this.Quantity_of_this_item = quantity;
        }

        public double totalPriceofthis
        {
            get => GoodsItem == null ? 0 : GoodsItem.goodprice * Quantity_of_this_item;
        }




    }
}
